<?php
/*
 * 增加用户经验,升级vip等级
 */

namespace App\Jobs\QiPao;

use App\Jobs\Job;
use App\Exceptions\BasicException;
use Illuminate\Support\Facades\Log;

class ExpJob extends Job
{
    protected $user_id;//用户id
    protected $gold;   //金币数量
    protected $type;   //类型
    protected $action_id;
    protected $down;//是否允许降级1允许默认为0不允许

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($user_id, $gold, $type = 1, $action_id = 0, $down = 0)
    {
        $this->user_id = $user_id;
        $this->gold = $gold;
        $this->type = $type;
        $this->action_id = $action_id;
        $this->down = $down;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        if(env('APP_ENV') != 'production'){
            Log::error('ExpJob:' . json_encode(['time' => getMillisecond(), 'data' => ['user_id' => $this->user_id, 'gold' => $this->gold, 'type' => $this->type, 'action_id' => $this->action_id, 'down' => $this->down,]]));
        }
        try {
            //增加vip经验值
            app('model_user')->addVipExp($this->user_id, $this->gold, $this->type, $this->action_id, $this->down);
        } catch (BasicException $exception) {
            echo $exception->getMessage();
        } catch (\Exception $exception) {
            Log::error('ExpJob:'.$exception->getMessage());
        }
    }
    
   /* public function fail($exception=null )
    {
        Log::error('ExpJob:'.$exception->getMessage());
    }*/
}
